/*	FormattedFieldFormItem.java
 *
 *	Copyright (c) Christopher Jacobs 2010
 *
 *	This file is part of MSGToolSuite_Swing ('this project').
 *
 *	This project is free software: you can redistribute it and/or modify it
 *	under the terms of the GNU General Public License as published by the Free
 *	Software Foundation, either version 3 of the License, or (at your option)
 *	any later version.
 *
 *	This project is distributed in the hope that it will be useful, but WITHOUT
 *	ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 *	FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 *	more details.
 *
 *	You should have received a copy of the GNU General Public License along with
 *	this project. If not, see <http://www.gnu.org/licenses/>.
 */
package edu.bu.manateem.msg.gui.component;

import java.text.Format;

import javax.swing.JFormattedTextField;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *	<p>
 *	
 *	</p>
 *
 *
 *	@author
 *		Christopher Jacobs
 *
 *	@version
 *		1.0
 *
 *	@changelog
 *		May 21, 2010	- Version 1.0.
 */
public abstract class FormattedFieldFormItem
	extends FormItem
{
	/*
	 * TYPES
	 */

	/*
	 * CONSTANTS
	 */

	// Serialize
	private static final long serialVersionUID = 1L;
	// Logging
	private static final Logger LOG =
		LoggerFactory.getLogger(FormattedFieldFormItem.class);
	
	/*
	 * FIELDS
	 */

	protected Format format;
	
	/*
	 * CONSTRUCTORS
	 */

	/**
	 *	<p>
	 *	
	 *	</p>
	 *
	 *	@since
	 *		
	 *
	 *
	 *	@param label
	 */
	public FormattedFieldFormItem(String label)
	{
		super(label);
	}
	
	public FormattedFieldFormItem(String label,String desc)
	{
		super(label,desc);
	}
	
	/*
	 * INITIALIZERS
	 */

	/*
	 * METHODS
	 */

	public String getText()
	{
		FormattedFieldFormItem.LOG.trace("return text from field");
		return ((JFormattedTextField) item).getText();
	}
	
	public Object getValue()
	{
		FormattedFieldFormItem.LOG.trace("return value from field");
		return ((JFormattedTextField) item).getValue();
	}
	
	protected abstract void initFormat();
	
	/**
	 *	<p>
	 *	
	 *	</p>
	 *
	 *	@since
	 *		
	 */
	@Override
	protected void initItem()
	{
		FormattedFieldFormItem.LOG.debug("init form item as formatted text field");
		
		// build format
		initFormat();
		
		// build item
		JFormattedTextField formItem = new JFormattedTextField(format);
		item = formItem;
	}
	
	public void setColumns(int cols)
	{
		((JFormattedTextField) item).setColumns(cols);
	}
	
	public void setText(String t)
	{
		FormattedFieldFormItem.LOG.trace("setting field text");
		((JFormattedTextField) item).setText(t);
	}
	
	public void setValue(Object value)
	{
		FormattedFieldFormItem.LOG.trace("setting field value");
		((JFormattedTextField) item).setValue(value);
	}
}
